<?php
$this->placeholder("navegacion")->set($this->navegacion($this->nav));
$autoOpen="false"; //esto se utiliza al final de la pagina para determinar si se abre o no el dialog al iniciar
?>
<div style="width: 800px" class="center-block">
<?php
//$this->placeholder("navegacion")->set($this->navegacion($this->nav));

$domConfig = Zend_Registry::get('domConfig');
$perfil = App_Perfil::getInstance();
$perfil->cargar("VARIABLES");
if (!$perfil->modificar()) {
    $this->formvariable->makeStatic();
}

echo $this->formvariable;
$tipovalor = ($this->formvariable->tiponaturaleza->getvalue()==1)?"valornum":"valortexto";

if ($this->verform2){
    echo $this->formdimension;
}
?>
</div>

<div id="dialog-form" title="Dimensión" style="display:none;">
<?php if(isset($this->errorMsg) && !empty($this->errorMsg)):
        $autoOpen="true";
?>
    <div id="priority_messages">
      <ul><li class="error_message"><?php echo $this->errorMsg; ?></li></ul>
    </div>
<?php endif; ?>
<span id="form-container"></span>
</div>



<?php
if ($perfil->crear() && $this->variable["tipogrado"]==2 && $this->variable["codvariable"]){
	
	$params1=App_Util_SafeUrl::encriptar(array("codvariable"=>$this->variable["codvariable"]),true);
?>
<div align="right" class="buttons">
  <a class="btn btn-primary" href="<?php echo $this->baseUrl("/variables/index/creardimension/{$params1}");?>">
  <span class="glyphicon glyphicon-plus-sign"></span> Crear Dimensi&oacute;n</a>
</div>
<?php }
if(count($this->datosdimensiones)>0):?>
<table id="table_id" align="center" class="display">
  <thead>
    <tr>
      <th width="20%">Nombre dimensi&oacute;n</th>
      <th width="20%">Unidad</th>
      <th width="10%">Instrumento</th>
      <th width="10%">Valor actual</th>
      <th width="15%">Acciones</th>
    </tr>
  </thead>
  <tbody>
	<?php foreach ($this->datosdimensiones as $key => $value):?>
    <tr>
      <td><?php echo $value["nombredimension"];?></td>
      <td><?php echo "{$value["nombreunidad"]}";?></td>
	  <td><?php echo $domConfig->INSTRUMENTO->$value["tipoinstrumento"];?></td>
      <td><?php
              echo "{$value[$tipovalor]}";
          ?>
      </td>
      <td>
        <?php
        $params=App_Util_SafeUrl::encriptar(array("coddimension"=>$value["coddimension"],"codvariable"=>$this->variable["codvariable"]),true);
        $tools = new App_Util_ToolButton();
        $tools->add($this->baseUrl("/variables/index/creardimension/{$params}"), "Modificar", "glyphicon glyphicon-pencil", true);
        $tools->add($this->baseUrl("/variables/index/usuariosdimension/{$params}"), "Asignar responsables", "glyphicon glyphicon-user", true);
        $tools->add($this->baseUrl("/variables/index/historicodimension/{$params}"), "Datos históricos", "glyphicon glyphicon-list-alt", true);
        if ($perfil->eliminar() && $this->variable["tipogrado"]==2 ){
            $tools->addDelete($this->baseUrl("/variables/index/eliminardimension/{$params}"),true);
        }
        echo $tools->render();
   		?>
      </td>
    </tr>
  <?php  endforeach;?>
  </tbody>
</table>

<script type="text/javascript">
 $(function() {
	$('#table_id').dataTable({
		"bJQueryUI": true,
		"bAutoWidth": false,
 		"sPaginationType": "full_numbers",
 		"bStateSave": true,
 		"aoColumns": [
 	 		 			{ "sType": "numeric" },
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			{ "bSortable": false, "bSearchable": false }
 	 		 		 ]
 	 		  		
	});

});
</script>
<?php else:?>
<br/>
<?php echo $this->mensajes("No existen registros");?>
<?php endif;?>

<script type="text/javascript">
$(function() {

	$( "#tiponaturaleza" ).change(function() {
		 var value = $( this ).val();
		 if (value==2){
			 $('#tipocuantitativa').closest("div.form-group").hide();
		 }else{
			$('#tipocuantitativa').closest("div.form-group").show();
		 }
	});

	$("#dialog-form").dialog({
		autoOpen: <?php echo $autoOpen;?>,
		height: 510,
		width: 750,
		modal: true,
		buttons: {
			'Cerrar': function() {
				$(this).dialog('close');
			}
		}
	});
	
	$('.link-asignar').click(function(e) {
		e.preventDefault();
		$("#form-container").load($(this).attr("href"), function(response, status, xhr) {
			$("#dialog-form").dialog("open");
		});
	});

		
});
</script>